package localdatatime;


import org.junit.Test;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
 * @author 真香
 * @create 2021-08-08 16:16
 */
public class Demo1 {


    /**
     * 时间校正器
     *  TemporalAdjuster
     */
    @Test
    public void test01(){
        LocalDateTime ldt = LocalDateTime.now();
        System.out.println(ldt);
        // 指定月中的天
        LocalDateTime ld2 = ldt.withDayOfMonth(10);
        System.out.println(ld2);

        // 下一个周日是什么时间
        LocalDateTime nextSunday = ldt.with(TemporalAdjusters.next(DayOfWeek.SUNDAY));
        System.out.println(nextSunday);

        // 自定义 获取下一个工作日的时间
        LocalDateTime ldt5 = ldt.with((l) -> {
            LocalDateTime ldt4 = (LocalDateTime) l;
            DayOfWeek dayOfWeek = ldt4.getDayOfWeek();
            if (dayOfWeek.equals(DayOfWeek.FRIDAY)) {
                return ldt4.plusDays(3);
            } else if (dayOfWeek.equals(DayOfWeek.SATURDAY)) {
                return ldt4.plusDays(2);
            }else {
                return ldt4.plusDays(1);
            }
        });
        System.out.println(ldt5);
    }



}
